<template>
	<view style="width: 100%;background-color: #FFFFFF;">
		<view class="department-name">
			部门名称：
			<input class="uni-input" name="input"  v-model="departmentname" placeholder="请填写部门名称" />
		</view>
		<!-- <view class="department-manager">请选择部门经理</view>
		<input class="uni-input department-manager-input" name="input" placeholder="输入姓名" />
		<view class="invite-colleagues">
			<view class="invite-colleagues-text">如果该同事尚未注册，请点击右边按钮</view>

			<view class="invite-colleagues-bnt">邀请同事</view>
		</view> -->
		<!-- <view class="colleagues">
			<view class="colleagues-tip"></view>
			<view class="colleagues-right">
				<view class="colleagues-message">
					<view class="name">张大炮</view>
					<view class="phone-number">15398886988</view>
				</view>
				<view class="colleagues-add">
					<view class="colleagues-company">中山市科技有限公司</view>
					<view class="colleagues-add-bnt">添加</view>
				</view>
			</view>
		</view> -->
		<!-- <view class="colleagues">
			<view class="colleagues-tip"></view>
			<view class="colleagues-right">
				<view class="colleagues-message">
					<view class="name">张大炮</view>
					<view class="phone-number">15398886988</view>
				</view>
				<view class="colleagues-add">
					<view class="colleagues-company">中山市科技有限公司</view>
					<view class="colleagues-add-bnt">添加</view>
				</view>
			</view>
		</view>
		<view class="colleagues-name">
			经理姓名：
			<view class="name">{{ 1 }}</view>
		</view> -->
		<view class="bnt">
			<!-- <view class="refresh">刷新</view> -->
			<view class="bnt-add tCenter" @click="adddepartment">确定</view>
		</view>
		<backnext></backnext>
		<!-- 底部导航 -->
		<footernav pagePath='user'></footernav>
		<!-- 加载动画 -->
		<loading v-if="!isloading()"></loading>
	</view>
</template>

<script>
import {userinfo} from '../../common/api/user.js'; //引进requst方法
import {adddept,deptedit} from '../../common/api/department.js'; //引进requst方法
export default {
	data() {
		return {
			companyid:"",
			departmentname:"",
			detaildata:"",
		}
	},
	methods: {
		adddepartment() {
			
			if(!this.departmentname){
					uni.showToast({
						icon: 'none',
						title: '请输入部门名称',
						duration: 2000
					});
			}else{
				if(this.detaildata){
					deptedit({name:this.departmentname,deptid:this.detaildata.id,id:this.detaildata.id}).then(res=>{
						console.log(res)
						if(res.data.code==200){
							uni.showToast({
								icon: 'none',
								title: '修改成功',
								duration: 2000
							});
							setTimeout(()=>{
								uni.reLaunch({
									url: '/pages/Departmentmanagement/departmentManagement'
								});
							},1000)
							
							// this.backrefresh('123');
						}else{
							uni.showToast({
								icon: 'none',
								title: res.data.message,
								duration: 2000
							});
						}
						
					})
					
				}else{
					adddept({name:this.departmentname,companyid:this.companyid}).then(res=>{
						console.log(res)
						if(res.data.code==200){
							uni.showToast({
								icon: 'none',
								title: '添加成功',
								duration: 2000
							});
							// uni.navigateBack();
							this.backrefresh('123')
						}else{
							uni.showToast({
								icon: 'none',
								title: res.data.message,
								duration: 2000
							});
						}
						
					})
				}
				
			
			}
		}
	},
	onLoad(event) {
		if(event&&event.detaildata){
				try {
					this.detaildata = JSON.parse(decodeURIComponent(event.detaildata));
					console.log(this.detaildata);
					this.departmentname=this.detaildata.departname;
				} catch (error) {
					this.detaildata = JSON.parse(event.detaildata);
					console.log(this.detaildata);
				}
		}
		
		
		userinfo({}).then(res=>{
			console.log(res)
			this.companyid=res.data.data.companyid;		
			
		})
	},
			
};
</script>

<style lang="scss">
.department-name {
	display: flex;
	align-items: center;
	margin: 10px;
	border-bottom: 1px solid #eee;
}
.department-manager {
	margin: auto;
	text-align: center;
	color: rgba(166, 166, 166, 1);
	font-size: 12px;
}
.department-manager-input {
	border: 1px solid #eee;
	width: 90%;
	margin: auto;
}
.invite-colleagues {
	color: rgba(166, 166, 166, 1);
	font-size: 12px;
	display: flex;
	align-items: center;
	text-align: center;
	margin-top: 20px;
}
.invite-colleagues-bnt {
	width: 91px;
	height: 33px;
	color: rgba(255, 255, 255, 1);
	background-color: rgba(42, 130, 228, 1);
	border-radius: 18px;
	line-height: 33px;
	font-size: 15px !important;
	margin-right: 5px;
}
.invite-colleagues-text {
	margin: auto;
}
.colleagues {
	width: 100%;
	display: flex;
	align-items: center;
	padding: 18px 0;
	.colleagues-tip {
		width: 55px;
		height: 55px;
		left: 5px;
		top: 313px;
		color: rgba(80, 80, 80, 1);
		background-color: rgba(153, 153, 153, 1);
		border-radius: 28px;
		margin-left: 10px;
	}
	.colleagues-right {
		display: flex;
		align-items: center;
		justify-content: space-between;
		width: 77%;
		margin-left: 20px;
		border-bottom: 1px solid #eee;
		padding-bottom: 10px;
		.name {
			color: rgba(80, 80, 80, 1);
			font-size: 18px;
		}
		.phone-number {
			color: rgba(166, 166, 166, 1);
			font-size: 16px;
		}
		.colleagues-add {
			.colleagues-company {
				color: rgba(166, 166, 166, 1);
				font-size: 16px;
			}
			.colleagues-add-bnt {
				width: 53px;
				height: 27px;
				color: rgba(255, 255, 255, 1);
				background-color: rgba(42, 130, 228, 1);
				border-radius: 18px;
				font-size: 11px;
				line-height: 27px;
				text-align: center;
				margin-left: auto;
			}
		}
	}
}
.colleagues-name {
	color: rgba(80, 80, 80, 1);
	display: flex;
	margin-left: 10px;
	font-size: 15px;
}
.bnt {
	// color: rgba(255, 255, 255, 1);
	font-size: 15px;
	// display: flex;
	// justify-content: space-between;
	width: 70%;
	margin: auto;
	color: white;
	margin-top: 50px;
	.bnt-add {
		background-color: rgba(42, 130, 228, 1);
		border-radius: 8px;
		// padding: 5px 35px;
		line-height: 42px;
	}
	.refresh {
		background-color: rgba(42, 130, 228, 1);
		border-radius: 18px;
		padding: 5px 35px;
	}
}
</style>
